//
//  UserAccountViewModel.swift
//  JIMWeiBo
//
//  Created by 陈恒均 on 2018/2/11.
//  Copyright © 2018年 陈恒均. All rights reserved.
//

import UIKit

class UserAccountViewModel {
    
    static let shareInstance : UserAccountViewModel = UserAccountViewModel()
    
    var account : UserAccount?
    
    var accountPath : String {
        let accountPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        
        return (accountPath as NSString).appendingPathComponent("account.plist")
    }
    
    var isLogin : Bool{
        if account == nil {
            return false
        }
        guard let expiresDate = account?.expires_date else{
            return false
        }
        
        return  expiresDate.compare(NSDate() as Date) == ComparisonResult.orderedDescending
    }
    
    
    
    init() {
        account = NSKeyedUnarchiver.unarchiveObject(withFile: accountPath) as? UserAccount
    }
}
